package toanstt.com.gameplay;



import toanstt.com.MatchUp.App;
import toanstt.com.MatchUp.MainActivity;
import toanstt.com.MatchUp.SCR;
import toanstt.com.MatchUp.Sound2;
import toanstt.com.MatchUp.T;
import android.graphics.Canvas;
import android.view.MotionEvent;

public class G
{
	int temp_x,temp_y;
	int action, actionCode;
	public static long TIME_START;
	
	public static CellTable celltable;
	//public static Keys keys;
	public static History history;
	public static SaveGame savegame;
	public static long timestart;
	public static float time;
	public static GameStatus gamestatus;
	public G()
	{
		time =0;
		history = new History();
		celltable = new CellTable();
		//keys = new Keys();
		savegame = new SaveGame();
		gamestatus = new GameStatus();
	}
	static public void NewGame(int i1,int i2)
	{
		
		T.IS_BUSY = true;
		T.SCREEN = SCR.GAME;
		T.GAME_I1 = i1;
		T.GAME_I2 = i2;
		timestart = App.currenttime;
		T.DELAY_TIME =0;
		celltable.NewGame(i1,i2);
		gamestatus.NewGame(i1, i2);
		
		history.NewGame();
		T.sounds.Play(Sound2.SLIPALL);
		T.IS_BUSY = false;
	}
	public void Draw(Canvas canvas)
	{
		time = App.currenttime - T.DELAY_TIME - timestart + T.PAST_TIME;
		if(T.THEME_WHITE == true)
			canvas.drawBitmap(T.TBITMAP_THEME_WHITE.bitmap[0], 0, 0, null);
		else
			canvas.drawBitmap(T.TBITMAP_THEME_BLACK.bitmap[0], 0, 0, null);
		celltable.Draw(canvas);
		//keys.Draw(canvas);
		///canvas.drawText(""+time, 133, 133, T.paint);
		
		
		gamestatus.Draw(canvas);
		//T.bitmapfont1.drawString(canvas, "Toan oi toan", 100, 100, 0);
	}
	public void Update()
	{
		
	}
	public void touch(MotionEvent mo)
	{
		
		action = mo.getAction();
		actionCode = action & MotionEvent.ACTION_MASK;
		temp_x = (int)mo.getX();
		temp_y = (int)mo.getY();
		if(T.IS_BUSY == false)
		{
		celltable.touch(mo);
		gamestatus.touch(mo);
		}
		/*switch(action)
		{
			case MotionEvent.ACTION_DOWN:
				if(temp_y < 50)
					if(temp_x > T.DISPLAY_WIDTH -50)
						MainActivity.activity.finish();
			break;
			
			case MotionEvent.ACTION_UP:
			break;
			
			case MotionEvent.ACTION_MOVE:
			break;

		}*/
	}
}
